package com.njym.java.security.admin.rest;

import com.njym.java.security.admin.biz.TaskListBiz;
import com.njym.java.security.admin.entity.TaskList;
import com.njym.java.security.common.msg.ObjectRestResponse;
import com.njym.java.security.common.rest.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("taskList")
public class TaskListController extends BaseController<TaskListBiz, TaskList> {
    @Autowired
    private TaskListBiz taskListBiz;

    /**
     *跟据分类id查询出用户在该分类中已经完成的任务，即可再次分配的任务
     * @param list  前台传递过来的数组字符串
     * @param classId   任务分类id
     * @return
     */
    @RequestMapping(value = "/getClassifyTasks",method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse<TaskList> getClassifyTasks( @RequestParam String list, @RequestParam int classId){

        String[] arr = list.split(",");
        //前台传递把数组变为字符串传递过来，处理成数组
        List<Integer> ids = new ArrayList<>();
        for(String item : arr){
            ids.add(Integer.valueOf(item));
        }
        List<TaskList> tasks = taskListBiz.getTasks(ids, classId);
        //找到没有安排的任务
        Map<String, Object> data = new HashMap<>(1);
        data.put("tasks", tasks);
        return new ObjectRestResponse<>().rel(true).data(data);
    }
}